package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.platform.dto.user.RoleDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Role;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class RoleConverter {
    public static RoleDto do2Dto(Role domain){
        return Objects.isNull(domain) ? null: RoleDto.builder()
                .id(domain.getId())
                .name(domain.getName())
                .deleted(domain.getDeleted())
                .remark(domain.getRemark())
                .urls(CollectionUtils.isEmpty(domain.getUrls()) ? Collections.EMPTY_SET:
                        domain.getUrls().stream().map(UrlConverter::do2Dto).collect(Collectors.toSet()))
                .build();
    }

    public static List<RoleDto> do2Dto(List<Role> domain){
        return CollectionUtils.isEmpty(domain) ? java.util.Collections.emptyList() : domain.stream().map(RoleConverter::do2Dto).collect(Collectors.toList());
    }

    public static Role dto2Do(RoleDto dto){
        return Objects.isNull(dto) ? null: Role.builder()
                .id(dto.getId())
                .name(dto.getName())
                .deleted(dto.getDeleted())
                .remark(dto.getRemark())
                .urls(CollectionUtils.isEmpty(dto.getUrls()) ? Collections.EMPTY_SET:
                        dto.getUrls().stream().map(UrlConverter::dto2Do).collect(Collectors.toSet()))
                .build();
    }

    public static List<Role> dto2Do(List<RoleDto> hostDtoList){
        return CollectionUtils.isEmpty(hostDtoList) ? java.util.Collections.emptyList() : hostDtoList.stream().map(RoleConverter::dto2Do).collect(Collectors.toList());
    }
}
